home *** CD-ROM | disk | FTP | other *** search
- Path: newsbf02.news.aol.com!not-for-mail
- From: lennyl9150@aol.com (LennyL9150)
- Newsgroups: comp.lang.c
- Subject: Array initialization problem
- Date: 20 Apr 1996 11:08:03 -0400
- Organization: America Online, Inc. (1-800-827-6364)
- Sender: root@newsbf02.news.aol.com
- Message-ID: <4laukj$q4t@newsbf02.news.aol.com>
- Reply-To: lennyl9150@aol.com (LennyL9150)
- NNTP-Posting-Host: newsbf02.mail.aol.com
-
- Hi all. I have a problem initializing an array in a function that has an
- array size passed from another function. OK, before I get you more
- confused that's what my program does. It reads a data file, and puts the
- data in the link list. It also keeps track of how many elements are in
- this linked list. Then at some point I have a function that will process
- the data but it needs to have an array (actually more than one array) to
- do that. But when I call such a function with a value of number of
- elements in the linked list and try to declare an array to be the size of
- this number, Turbo C compiler gives an error saying that array's size must
- be a constant. I tried to cast it as a constant but it didn't work. So
- I searched my books on C and one did mention this problem, but did not
- give any suggestions. Below is a simple pseudocode in case I got you all
- confussed.
-
- main()
- {
- int cnt = 0;
- while (fscanf()) {
- create_link();
- ++cnt;
- } /* end while */
-
- make_matrix( cnt );
- }
-
- void make_matrix(int size)
- {
- int arr[size]; /* This is where compiler complains that size has to
- be a constant
- I tried casting but it did not help. */
- }
-
- Any sugestions are appreciatted. Thank you very much.
- Lenny
-
-
- This is Lenny reporting from the Sunshine State:
- "Today, once again, we have a 100% chance of showers and possible
- thunderstorms."
-
- lennyl9150@aol.com or lleyze@unf.edu
-